package cn.nuomi.shop.api.controller;

import cn.nuomi.shop.api.entity.Goods;
import cn.nuomi.shop.api.service.GoodsService;
import cn.nuomi.shop.api.service.impl.GoodsServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @date: 2021/4/27 13:56
 * @description:
 */

@WebServlet("/goodsListServlet")
public class GoodsListServlet  extends BaseServlet{

    private GoodsService goodsService = new GoodsServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try{
            List<Goods> list = goodsService.getGoodsList();

            resp.setHeader("Access-Control-Allow-Origin", "*");

            successResp(resp,list);
        }catch (RuntimeException e){
            e.printStackTrace();
            errorResp(resp,e.getMessage());
        }
    }
}
